<extend name="Base/common"/>
<block name="left"></block>
<block name="body">
	<div class="container">
		<div class="register">
			<img src="__IMG__/reg_img1.png" alt="" width="100%">
			<div class="reg_bar">
				<p class="phone_num clearfix"><input type="text" name="mobile" id="mobile" placeholder="手机号"></p>
				<p class="reg_pwd clearfix reg_password"><input type="text" placeholder="密码"><input name="password" id="password" value="" type="password"></p>
				<p class="reg_repwd clearfix reg_password"><input type="text" placeholder="确认密码"><input name="repassword" id="repassword" value="" type="password"></p>
				<p class="reg_code clearfix"><input type="text" name="code" id="code" placeholder="验证码"><input type="submit" class="btn" value="获取验证码" id="GetCode" ></p>
			</div>
			<span class="msg"></span>

			<div class="xieyi"><input id="checkbox" name="check" checked type="checkbox">我已阅读并同意<a href="{:U('Agreement/agreement')}">《用户协议》</a></div>
			<input type="button" value="注册" class="reg_btn">
		</div>
	</div>
<block name="script">
<script type="text/javascript">	
	$(document).ready(function(){
		/*密码框*/
		$(".reg_bar .reg_password").find("input[type='text']").focus(function() {
			var text_value = $(this).val();
		    if (text_value == this.defaultValue) {
		    var obj=$(this).parent(".reg_password")
		    $(this).hide();
		    obj.find("input[type='password']").show().focus();			    
		    }
		});
		$(".reg_bar .reg_password").find("input[type='password']").blur(function() {
		    var text_value = $(this).val();
		    if (text_value == "") {
		    var obj1=$(this).parent(".reg_password")			    
		    $(this).hide();
		    obj1.find("input[type='text']").show();
		    }
		});

		// 获取验证码
		$("#GetCode").click(function(){                               
				var mobile=$('#mobile').val();
                var reg=/^1[3|4|5|7|8]\d{9}$/;
                if (reg.exec(mobile)==null) {
                  $('.msg').html('手机号不匹配或不为空');
                	return false;
                }else{
                	$('.msg').html('');
               	}
                var url="{:U('User/send_verify')}";
                $.post(url,{mobile:mobile},function(data){
                    if(data.status){
                        setInt();
                    }else{       
                        $(".msg").html(data.msg);
                    }
                },'json')        
            })
            var count=60;
            var curCount;
            var objTime;
            function setTime(){ 
                if (curCount==0) {
                    clearInterval(objTime);
                    $('#GetCode').removeAttr('disabled');
                    $('#GetCode').css('background','#ff0000');
                    $('#GetCode').val('重发验证码');                    
                }else{  
                    curCount--; 
                    $('#GetCode').val(curCount + "秒后重发")
                }
            }

            function setInt() {
                curCount=count;             
                $('#GetCode').attr('disabled','true');
                $('#GetCode').css('background','#b1b1b1');
                $('#GetCode').val(curCount + "秒后重发")                                                
                objTime=setInterval(setTime,1000);
            }

	})
	$('.reg_btn').click(function(){
		var mobile=$('#mobile').val();
		var password=$('#password').val();
		var repassword=$('#repassword').val();
		var code=$('#code').val();
		var url="{:U('User/user_register_add')}";
		var reg=/^1[3|4|5|7|8]\d{9}$/;
		if(reg.exec(mobile)==null) {
             $('.msg').html('手机号不匹配或不为空');
             return false;
        }
        if(password==''){
        	$('.msg').html('密码不能为空');
            return false;
        }
        if(repassword==''){
        	$('.msg').html('确认密码不能为空');
            return false;
        }
        if(password!=repassword){
        	$('.msg').html('密码不相同');
            return false;
        }
        if(code==''){
        	$('.msg').html('验证码不能为空');
            return false;
        }
       var hasChk = $('#checkbox').is(':checked');
		if(hasChk){
    		/*已选中*/
		}else{
    		$('.msg').html('用户协议未选中');
            return false;
		}
		$.post(url,
			{
				phone:mobile,
				password:password,
				repassword:repassword,
				code:code,
			},function(data){
          		if(data.status){
          			$('.msg').html(data.msg);
          			setTimeout(link_url,2000);	
          		}else{
          			$('.msg').html(data.msg);
          		}
        },'json')   
        
		
	})
	function link_url(){
		var url_href="{:U('Index/index')}";;
		window.location.href=url_href;		
}
</script>
</block>

</block>